console.log("Remplacement de lien en cours...")

console.log("?")

var forms = document.getElementsByTagName("form");
var links = [];

function MesFunc()
{
	this.changeAppendChild = function()
	{
		Element.prototype.t_appendChild = Element.prototype.appendChild;
		Element.prototype.appendChild = function(e) { console.log(e); return this.t_appendChild(e);  }
		
	};
	
	this.init = function(old_window, new_window)
	{
		this.changeAppendChild();

		console.log(old_window);
		console.log(new_window);
		
		function ILocation() { };
		function IWindow() { };
		
		ILocation.prototype = { set href(nhref) { console.log("new href: "+nhref)} }
		ILocation.prototype.__defineSetter__("search", function() { console.log("search set !")});
		IWindow.prototype = {
			_location: new ILocation(),
			
			get location() {
				return this._location;
			},
			
			set location(newloc) {
				console.log("newloc: "+newloc)
			}

		};
		
		for (var i in old_window)
		{
			if (i == "location")
				continue;
			else
				IWindow.prototype[i] = old_window[i];
		}
		
		// IWindow.prototype.location = new ILocation();
		old_window.IWindow = IWindow;
		
	};
};

var body = document.getElementsByTagName("body")[0];
body.onclick = function()
{
	return new MesFunc();
}

var script = document.createElement("script");
script.type = "text/javascript";
script.text = "function window() { }; var window = {}; document.getElementsByTagName('body')[0].onclick().init(this,window); var window = new this['IWindow']()"
// body.appendChild(script);

var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++)
{
	//links[i].addEventListener("click", function(e) { e.preventDefault(); console.log("Link enclenched !") }, false);
	
}
var links = document.getElementsByTagName("form");
for (var i = 0; i < links.length; i++)
{
	links[i].addEventListener("submit", function(e) { e.preventDefault(); console.log("Submit enclenched !") }, false);
}

window.onchange = function(e) { console.log("onchange"); console.log(e); }


